//
//
//import com.education.common.utils.Util;
//import com.education.modules.questions.entity.QuestionsEntity;
//import org.apache.poi.hwpf.HWPFDocument;
//import org.apache.poi.hwpf.converter.WordToHtmlConverter;
//import org.apache.poi.xwpf.usermodel.IBodyElement;
//import org.apache.poi.xwpf.usermodel.XWPFDocument;
//import org.apache.poi.xwpf.usermodel.XWPFParagraph;
//import org.apache.poi.xwpf.usermodel.XWPFStyles;
//import org.jsoup.Jsoup;
//import org.jsoup.nodes.Document;
//import org.jsoup.nodes.Element;
//
//import javax.lang.model.util.Elements;
//import javax.xml.parsers.DocumentBuilderFactory;
//import javax.xml.parsers.ParserConfigurationException;
//import javax.xml.transform.*;
//import javax.xml.transform.dom.DOMSource;
//import javax.xml.transform.stream.StreamResult;
//import java.io.*;
//import java.util.ArrayList;
//import java.util.List;
//
//public class WordUtil {
//
//    public static void getDoc(){
//        //解析Word文档,暂时没有用了,用下面那个!
//        String path="D:\\testWord\\2019年江苏省南京市高一上学期期末考试_9099.docx";
//        InputStream is=null;
//        {
//            try {
//                is = new FileInputStream(path);
//            } catch (FileNotFoundException e) {
//                e.printStackTrace();
//            }
//        }
//        XWPFDocument doc=null;
//
//        {
//            try {
//                doc = new XWPFDocument(is);
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }
//        List<XWPFParagraph> paragraph=doc.getParagraphs();
//        List<IBodyElement> bodyElements=doc.getBodyElements();
//        XWPFStyles styles=doc.getStyles();
//        System.out.println(paragraph);
//        System.out.println(bodyElements);
//        System.out.println(styles);
//        for(XWPFParagraph p:paragraph){
//            System.out.println(p.getParagraphText());
//        }
//    }
//
//    public static void wordToHtml(){
//        //读取Word文档转为HTML文件
//        String path="D:\\testWord\\2019年江苏省南京市高一上学期期末考试_90999.doc";
//        String imagePath="D:\\testWord\\image\\";
//        String htmlPath="D:\\testWord\\testHtml.html";
//        File file=new File(path);
//        OutputStreamWriter outputStreamWriter = null;
//        if(!file.exists()){
//            System.out.println("文件不存在");
//        }else try {
//            //加载word文档生成XWPF对象
//            InputStream in = new FileInputStream(file);
//            //XWPFDocument document = new XWPFDocument(in);
//            HWPFDocument doc=new HWPFDocument(in);
//            org.w3c.dom.Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
//            WordToHtmlConverter wordToHtmlConverter=new WordToHtmlConverter(document);
//            //保存图片，并返回图片的相对路径
//            wordToHtmlConverter.setPicturesManager((content, pictureType, name, width, height) -> {
//                try (FileOutputStream out = new FileOutputStream(imagePath + name)) {
//                    out.write(content);
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//                return "image/" + name;
//            });
//            wordToHtmlConverter.processDocument(doc);
//            org.w3c.dom.Document htmlDocument = wordToHtmlConverter.getDocument();
//            DOMSource domSource = new DOMSource(htmlDocument);
//            StreamResult streamResult = new StreamResult(new File(htmlPath));
//            TransformerFactory tf = TransformerFactory.newInstance();
//            Transformer serializer = tf.newTransformer();
//            serializer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
//            serializer.setOutputProperty(OutputKeys.INDENT, "yes");
//            serializer.setOutputProperty(OutputKeys.METHOD, "html");
//            serializer.transform(domSource, streamResult);
//
//            //XHTML的方法.用不了
//            /*XHTMLOptions options = XHTMLOptions.create();
//            //图片目录
//            options.setExtractor(new FileImageExtractor(new File(imagePath)));
//            //html中图片的路径
//            options.URIResolver((new BasicURIResolver("image")));
//            outputStreamWriter = new OutputStreamWriter(new FileOutputStream(htmlPaht), "utf-8");
//            XHTMLConverter xhtmlConverter = (XHTMLConverter) XHTMLConverter.getInstance();
//            xhtmlConverter.convert(document, outputStreamWriter, options);*/
//
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        } catch (ParserConfigurationException e) {
//            e.printStackTrace();
//        } catch (TransformerConfigurationException e) {
//            e.printStackTrace();
//        } catch (TransformerException e) {
//            e.printStackTrace();
//        }
//
//    }
//
//    public static void main(String[] args) {
//        //getDoc();
//        //wordToHtml();
//        //读取解析之后的HTML文件,获取p标签并遍历.
//        File input = new File("D:\\testWord\\testHtml.html");
//        try {
//            Document doc = Jsoup.parse(input, "UTF-8", "http://example.com/");
//            org.jsoup.select.Elements pList=doc.getElementsByTag("p");
//            List<QuestionsEntity> questionList=new ArrayList<>();
//            int i=1;//题号
//            for(int j=0;j<pList.size();j++){
//                Element p=pList.get(j);
//                if(p.text().contains(i+".")){
//                    QuestionsEntity question=new QuestionsEntity();
//                    question.setStem(p.toString());
//                    questionList.add(question);
//                    i++;
//                }else if (p.text().contains("一、")||p.text().contains("二、")||p.text().contains("三、")||p.text().contains("四、")
//                        ||p.text().contains("五、")||p.text().contains("六、")||p.text().contains("七、")||p.text().contains("八、")
//                        ||p.text().contains("九、")||p.text().contains("十、")){
//                    continue;
//                }else{
//                    if(Util.isNotEmpty(questionList)&&questionList.size()>0){
//                        QuestionsEntity q=questionList.get(i-2);
//                        q.setStem(q.getStem()+p.toString());
//                    }
//                }
//
//            }
//            System.out.println(questionList);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//
//    }
//
//
//
//    }
//
